library(tidyverse)
library(dplyr)
library(reshape2)
library(ggplot2)
library(foreign)
library(readstata13)
library(cowplot)
library(gridExtra)
library(grid)
library(GGally)


opt = 
  theme_bw()+
  theme(
    axis.title.y = element_text(size = 11,vjust=1),
    axis.title.x = element_text(size = 11,vjust=0),
    # axis.text.x=element_text(size=10,color="black"),
    # axis.text.y=element_text(size=10,color="black"),
    panel.grid.minor = element_line(colour = NA),
    panel.grid.major.x = element_line(colour = NA),
    panel.grid.major.y = element_line(linetype="dotted", size=.8),
    # panel.grid.major.y = ggplot2::element_line(color = "#cbcbcb"), 
    panel.border = element_blank(),
    axis.line.y = element_blank(),
    axis.line.x = element_blank(),
    axis.line=element_line(),
    legend.position = "bottom", legend.title = element_blank(), 
    strip.text= element_text(face = "bold", size=12),  
    plot.title = element_text(size=12, vjust=1, hjust =.5, face = "bold"),
    strip.background = element_rect(colour = NA, fill = NA)
  )


setwd("")


########################################################
# Figure 2
########################################################

## war
data <-read.dta13("fig2.dta")

data$model = factor(data$model, levels = c(0,1,2,3,4,5,10,15))

p1 = 
  data %>% 
  filter(type==1) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr), size=1.2, fatten = 1.7)+  
  ylab("")+ 
  xlab("")+
  ggtitle("1. War and Female Legislators")+
  geom_hline(yintercept=0, lty=2, color="red")+
  # theme(panel.background = element_rect(fill='transparent'))+
  opt
  
p2 = 
  data %>% 
  filter(type==2 & var =="newwar") %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr),
                  size=1.2, fatten = 1.7)+
  # scale_color_manual(labels=c("Recent war","Ongoing","New war"), values=c("black", "gray40", "gray80"))+
  ylab("")+ 
  xlab("")+
  ggtitle("2. New War and Female Legislators")+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt


p3 = 
  data %>% 
  filter(type==2 & var =="ongoingwar") %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr),
                  size=1.2, fatten = 1.7)+
  # scale_color_manual(labels=c("Recent war","Ongoing","New war"), values=c("black", "gray40", "gray80"))+
  ylab("")+ 
  xlab("")+
  ggtitle("3. Ongoing War and Female Legislators")+
  scale_y_continuous(breaks = seq(-1.5, .5, by =.5))+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt


p4 = 
  data %>% 
  filter(type==2 & var =="recentwar") %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr),
                  size=1.2, fatten = 1.7)+
  # scale_color_manual(labels=c("Recent war","Ongoing","New war"), values=c("black", "gray40", "gray80"))+
  ylab("")+ 
  xlab("")+
  ggtitle("4. Recent War and Female Legislators")+
  scale_y_continuous(breaks = seq(-.5, 1.5, by =.5))+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt


## duration

p5 =
  data %>% 
  filter(type==3) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr), size=1.2, fatten = 1.7)+  
  ylab("")+ 
  xlab("")+
  ggtitle("5. War Duration and Female Legislators")+
  geom_hline(yintercept=0, lty=2, color="red") +
  opt

## battle deaths

p6 =
  data %>% 
  filter(type==4) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr), size=1.2, fatten = 1.7)+  
  ylab("")+ 
  xlab("")+
  ggtitle("6. Battle Deaths and Female Legislators")+
  geom_hline(yintercept=0, lty=2, color="red") +
  opt


## Irregular Leadership Changes

p7 =
  data %>% 
  filter(type==5) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr), size=1.2, fatten = 1.7)+  
  ylab("")+ 
  xlab("")+
  ggtitle("7. Irregular Leadership Changes and Female Legislators")+
  geom_hline(yintercept=0, lty=2, color="red") +
  opt

p <- grid.arrange(p1, p2, p3, p4, p5, p6, p7, ncol=2)
ggsave(p, file="fig2.pdf", width=10, height=10)

########################################################
# Figure 3
########################################################

### Figure A8

data <-read.dta13("fig3.dta")

data$dep2 = c(rep(1,8),rep(2,8),rep(3,8),rep(4,8),rep(5,8),rep(6,8))
data$dep2 = factor(data$dep2, levels = c(1:6), 
                   labels= c("1. Political empowerment","2. Civil liberty", "3. Civil participation", 
                             "4. Political participation", "5. Power distribution", "6. Legislators (%)"))
data$model = factor(data$model, levels = c(0,1,2,3,4,5,10,15))

ggplot(data) +
  facet_wrap( ~ dep2) + 
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, group=dep), size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+  
  ylab("")+ 
  xlab("")+
  ggtitle("Effect of War on Women's Political Empowerment and Its Components (V-Dem ver.6.2)")+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt

ggsave(file="fig3.pdf", width=9, height=5, units = "in")

########################################################
# Figure 4
########################################################

data <-read.dta13("fig4.dta")

p1 = 
  data %>% 
  filter(type==1) %>% 
  ggplot(aes(group=var, color=var)) +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Interstate","Intrastate"), values =c("gray70", "black"))+
  ylab("")+ 
  xlab("")+
  ggtitle("1. Interstate vs. Intrastate Wars")+
  geom_hline(yintercept=0, lty=2, color="red") + 
  annotate(geom="text", x=2.2, y=.8, label="Interstate", color="gray70", size=3) +
  annotate(geom="text", x=2.4, y=-1.2, label="Intrastate", color="black", size=3) +
  theme_bw()+
  opt +
  theme(legend.position = "none")

p2 = 
  data %>% 
  filter((var =="new_intrawar"| var =="newinter") & (type ==2 | type==3)) %>% 
  ggplot(aes(group=var, color=var)) +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  ylab("")+ 
  xlab("")+
  scale_color_manual(labels=c("Interstate","Intrastate"), values =c("black", "gray70"))+
  ggtitle("2. New Intrastate and Interstate Wars")+
  geom_hline(yintercept=0, lty=2, color="red") + 
  annotate(geom="text", x=2.3, y=.4, label="Interstate", color="gray70", size=3) +
  annotate(geom="text", x=1.4, y=-1, label="Intrastate", color="black", size=3) +
  theme_bw()+
  opt +
  theme(legend.position = "none")

p3 = 
  data %>% 
  filter((var =="ongoingintra"| var =="ongoinginter") & (type ==2 | type==3)) %>% 
  ggplot(aes(group=var, color=var)) +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  ylab("")+ 
  xlab("")+
  scale_color_manual(labels=c("Interstate","Intrastate"), values =c("gray70", "black"))+
  ggtitle("3. Ongoing Intrastate and Interstate Wars")+
  geom_hline(yintercept=0, lty=2, color="red") + 
  annotate(geom="text", x=2, y=1, label="Interstate", color="gray70", size=3) +
  annotate(geom="text", x=1.4, y=-.7, label="Intrastate", color="black", size=3) +
  theme_bw()+
  opt +
  theme(legend.position = "none")

p4 = 
  data %>% 
  filter((var =="recentintra"| var =="recentinter") & (type ==2 | type==3)) %>% 
  ggplot(aes(group=var, color=var)) +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Interstate","Intrastate"), values =c("gray70", "black"))+
  ylab("")+ 
  xlab("")+
  ggtitle("4. Recent Intrastate and Interstate Wars")+
  geom_hline(yintercept=0, lty=2, color="red") + 
  annotate(geom="text", x=1.7, y=.5, label="Interstate", color="gray70", size=3) +
  annotate(geom="text", x=1.4, y=-.8, label="Intrastate", color="black", size=3) +
  theme_bw()+
  opt +
  theme(legend.position = "none")

p5 = 
  data %>% 
  filter(type==4 & var =="intrawardur") %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr), size=1.2, fatten = 1.7)+  
  ylab("")+ 
  xlab("")+
  ggtitle("5. Intrastate war duration")+
  geom_hline(yintercept=0, lty=2, color="red") + 
  theme_bw()+
  opt +
  theme(legend.position = "none")

p6 = 
  data %>% 
  filter(type==5 & var =="ln_intradeaths") %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr), size=1.2, fatten = 1.7)+  
  ylab("")+ 
  xlab("")+
  ggtitle("6. Intrastate war battle deaths")+
  geom_hline(yintercept=0, lty=2, color="red") + 
  theme_bw()+
  opt +
  theme(legend.position = "none")

p <- grid.arrange(p1, p2, p3, p4, p5, p6, ncol=2)
ggsave(p, file="fig4.pdf", width=10, height=7.5)


########################################################
# Figure 5
########################################################


data <-read.dta13("fig5.dta")
data$model = factor(data$model, levels = c(0,1,2,3,4,5,10,15))

p1 = 
  data %>% 
  filter(type==1) %>% 
  ggplot(aes(group=var, color=var)) +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Ongoing","Ending"), values =c("gray70", "black"))+
  ylab("")+ 
  xlab("")+
  ggtitle("1. Full sample")+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))


p2 = 
  data %>% 
  filter(type==2) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, group=var, color=var),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Ongoing","Ending"), values =c("gray70", "black"))+
  ylab("")+ 
  xlab("")+
  ggtitle("2. Post-1985 period")+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))


p3 = 
  data %>% 
  filter(type==3) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, group=var, color=var),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Ongoing","Ending"), values =c("gray70", "black"))+
  ylab("")+ 
  xlab("")+
  ggtitle("3. East Europe and Central Asia")+
  # scale_y_continuous(breaks = seq(-1.5, .5, by =.5))+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))

p4 = 
  data %>% 
  filter(type==4) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, group=var, color=var),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Ongoing","Ending"), values =c("gray70", "black"))+
  ylab("")+ 
  xlab("")+
  ggtitle("4. Latin America")+
  # scale_y_continuous(breaks = seq(-1.5, .5, by =.5))+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))

p5 = 
  data %>% 
  filter(type==5) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, group=var, color=var),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Ongoing","Ending"), values =c("gray70", "black"))+
  ylab("")+ 
  xlab("")+
  ggtitle("5. Middle East")+
  # scale_y_continuous(breaks = seq(-1.5, .5, by =.5))+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))

p6 = 
  data %>% 
  filter(type==6) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, group=var, color=var),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Ongoing","Ending"), values =c("gray70", "black"))+
  ylab("")+ 
  xlab("")+
  ggtitle("6. South-East Asia")+
  # scale_y_continuous(breaks = seq(-1.5, .5, by =.5))+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))


p7 = 
  data %>% 
  filter(type==7) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, group=var, color=var),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Ongoing","Ending"), values =c("gray70", "black"))+
  ylab("")+ 
  xlab("")+
  ggtitle("7. South Asia")+
  # scale_y_continuous(breaks = seq(-1.5, .5, by =.5))+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))


p8 = 
  data %>% 
  filter(type==8) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, group=var, color=var),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Ongoing","Ending"), values =c("gray70", "black"))+
  ylab("")+ 
  xlab("")+
  ggtitle("8. Sub-Saharan Africa")+
  # scale_y_continuous(breaks = seq(-1.5, .5, by =.5))+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))

p <- grid.arrange(p1, p2, p3, p4,p5, p6, p7, p8, ncol=2)
ggsave(p, file="fig5.pdf", width=10, height=10)


########################################################
# Figure 6
########################################################


### Fig A20

data <-read.dta13("fig6a.dta")

data$dep2 = c(rep(1,16),rep(2,16),rep(3,16),rep(4,16),rep(5,16),rep(6,16))
data$dep2 = factor(data$dep2, levels = c(1:6), 
                   labels= c("1. Political empowerment","2. Civil liberty", "3. Civil participation", 
                             "4. Political participation", "5. Power distribution", "6. Legislators (%)"))
data$model = factor(data$model, levels = c(0,1,2,3,4,5,10,15))

ggplot(data, aes(group=var, color=var)) +
  facet_wrap( ~ dep2) + 
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, group=var, color=var),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Ongoing","Ending"), values =c("gray60","black"))+
  ylab("")+ 
  xlab("")+
  ggtitle("Effect of ongoing civil war and civil war termination (only SSF) ")+
  geom_hline(yintercept=0, lty=2, color="red") + 
  theme_bw()+
  opt 

ggsave(file="fig6a.pdf", width=10, height=6, units = "in")

### Fig A21

data <-read.dta13("fig6b.dta")

data$dep2 = c(rep(1,16),rep(2,16),rep(3,16),rep(4,16),rep(5,16),rep(6,16))
data$dep2 = factor(data$dep2, levels = c(1:6), 
                   labels= c("1. Political empowerment","2. Civil liberty", "3. Civil participation", 
                             "4. Political participation", "5. Power distribution", "6. Legislators (%)"))
data$model = factor(data$model, levels = c(0,1,2,3,4,5,10,15))

ggplot(data, aes(group=var, color=var)) +
  facet_wrap( ~ dep2) + 
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, group=var, color=var),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Ongoing","Ending"), values =c("gray60","black"))+
  ylab("")+ 
  xlab("")+
  ggtitle("Effect of ongoing civil war and civil war termination (except SSF) ")+
  geom_hline(yintercept=0, lty=2, color="red") + 
  theme_bw()+
  opt 

ggsave(file="fig6b.pdf", width=10, height=6, units = "in")


########################################################
# Supporting Appendix
########################################################

### Fig A1

corrdata <- read.dta13("/Users/nk/Dropbox/DATA/Gender/IO-women-empowerment-master/NK replication/corr.dta")
corrdata <- corrdata[,c(4:60)]


c1 <- 
  corrdata %>% 
  select(starts_with("F0S1")) %>% 
  rename("empowerment"=F0S1v2x_gender,
         "civil liberty"=F0S1v2x_gencl, 
         "civil society part"=F0S1v2x_gencs, 
         "power dist"=F0S1v2pepwrgen, 
         "legislators"=F0S1v2lgfemleg, 
         "political part"=F0S1v2x_genpp) %>%
  ggcorr(layout.exp=1, label = TRUE, label_round = 2, hjust=.7)+
  ggtitle(expression("1-year"~Delta))+
  theme(plot.title = element_text(size=18,vjust=1, hjust = 0, face = "bold"),
        plot.margin = margin(.5, .5, .5, .5, "cm"))


c2 <- corrdata %>% 
  select(starts_with("F2S3")) %>% 
  rename("empowerment"=F2S3v2x_gender,
         "civil liberty"=F2S3v2x_gencl, 
         "civil society part"=F2S3v2x_gencs, 
         "power dist"=F2S3v2pepwrgen, 
         "legislators"=F2S3v2lgfemleg, 
         "political part"=F2S3v2x_genpp) %>%
  ggcorr(layout.exp=1, label = TRUE, label_round = 2, hjust=.7)+
  ggtitle(expression("3-year"~Delta))+
  theme(plot.title = element_text(size=18,vjust=1, hjust = 0, face = "bold"),
        plot.margin = margin(.5, .5, .5, .5, "cm"))

c3 <- corrdata %>% 
  select(starts_with("F4S5")) %>% 
  rename("empowerment"=F4S5v2x_gender,
         "civil liberty"=F4S5v2x_gencl, 
         "civil society part"=F4S5v2x_gencs, 
         "power dist"=F4S5v2pepwrgen, 
         "legislators"=F4S5v2lgfemleg, 
         "political part"=F4S5v2x_genpp) %>%
  ggcorr(layout.exp=1, label = TRUE, label_round = 2, hjust=.7)+
  ggtitle(expression("5-year"~Delta))+
  theme(plot.title = element_text(size=18,vjust=1, hjust = 0, face = "bold"),
        plot.margin = margin(.5, .5, .5, .5, "cm"))

c4 <- corrdata %>% 
  select(starts_with("F10S11")) %>% 
  rename("empowerment"= F10S11v2x_gender,
         "civil liberty"= F10S11v2x_gencl, 
         "civil society part"= F10S11v2x_gencs, 
         "power dist"= F10S11v2pepwrgen, 
         "legislators"= F10S11v2lgfemleg, 
         "political part"= F10S11v2x_genpp 
  ) %>%
  ggcorr(layout.exp=1, label = TRUE, label_round = 2, hjust=.7)+
  ggtitle(expression("11-year"~Delta))+
  theme(plot.title = element_text(size=18,vjust=1, hjust = 0, face = "bold"),
        plot.margin = margin(.5, .5, .5, .5, "cm"))

p <- grid.arrange(c1, c2, c3, c4, ncol=2)
ggsave(p, file="correlation.pdf", width=14, height=10)


### Fig A2

c1 <- 
  corrdata %>% 
  filter(v_demo==1) %>% 
  select(starts_with("F0S1")) %>% 
  rename("empowerment"=F0S1v2x_gender,
         "civil liberty"=F0S1v2x_gencl, 
         "civil society part"=F0S1v2x_gencs, 
         "power dist"=F0S1v2pepwrgen, 
         "legislators"=F0S1v2lgfemleg, 
         "political part"=F0S1v2x_genpp) %>%
  ggcorr(layout.exp=1, label = TRUE, label_round = 2, hjust=.7)+
  ggtitle(expression("1-year"~Delta))+
  theme(plot.title = element_text(size=18,vjust=1, hjust = 0, face = "bold"),
        plot.margin = margin(.5, .5, .5, .5, "cm"))


c2 <- corrdata %>% 
  filter(v_demo==1) %>% 
  select(starts_with("F2S3")) %>% 
  rename("empowerment"=F2S3v2x_gender,
         "civil liberty"=F2S3v2x_gencl, 
         "civil society part"=F2S3v2x_gencs, 
         "power dist"=F2S3v2pepwrgen, 
         "legislators"=F2S3v2lgfemleg, 
         "political part"=F2S3v2x_genpp) %>%
  ggcorr(layout.exp=1, label = TRUE, label_round = 2, hjust=.7)+
  ggtitle(expression("3-year"~Delta))+
  theme(plot.title = element_text(size=18,vjust=1, hjust = 0, face = "bold"),
        plot.margin = margin(.5, .5, .5, .5, "cm"))

c3 <- corrdata %>% 
  filter(v_demo==1) %>% 
  select(starts_with("F4S5")) %>% 
  rename("empowerment"=F4S5v2x_gender,
         "civil liberty"=F4S5v2x_gencl, 
         "civil society part"=F4S5v2x_gencs, 
         "power dist"=F4S5v2pepwrgen, 
         "legislators"=F4S5v2lgfemleg, 
         "political part"=F4S5v2x_genpp) %>%
  ggcorr(layout.exp=1, label = TRUE, label_round = 2, hjust=.7)+
  ggtitle(expression("5-year"~Delta))+
  theme(plot.title = element_text(size=18,vjust=1, hjust = 0, face = "bold"),
        plot.margin = margin(.5, .5, .5, .5, "cm"))

c4 <- corrdata %>% 
  filter(v_demo==1) %>% 
  select(starts_with("F10S11")) %>% 
  rename("empowerment"= F10S11v2x_gender,
         "civil liberty"= F10S11v2x_gencl, 
         "civil society part"= F10S11v2x_gencs, 
         "power dist"= F10S11v2pepwrgen, 
         "legislators"= F10S11v2lgfemleg, 
         "political part"= F10S11v2x_genpp 
  ) %>%
  ggcorr(layout.exp=1, label = TRUE, label_round = 2, hjust=.7)+
  ggtitle(expression("11-year"~Delta))+
  theme(plot.title = element_text(size=18,vjust=1, hjust = 0, face = "bold"),
        plot.margin = margin(.5, .5, .5, .5, "cm"))

p <- grid.arrange(c1, c2, c3, c4, ncol=2)
ggsave(p, file="correlation_demo.pdf", width=14, height=10)


### Fig A3

corrdata <- read.dta13("/Users/nk/Dropbox/DATA/Gender/IO-women-empowerment-master/NK replication/corr.dta")

corrdata %>% 
  select("v2x_gender", "v2x_gencl", "v2x_gencs","v2x_genpp", "v2pepwrgen", "v2lgfemleg") %>% 
  rename("empowerment"= v2x_gender,
         "civil liberty"= v2x_gencl, 
         "civil society part"= v2x_gencs, 
         "power dist"= v2pepwrgen, 
         "legislators"= v2lgfemleg, 
         "political part"= v2x_genpp 
  ) %>%
  ggcorr(layout.exp=1, label = TRUE, label_round = 2, hjust=.7)+
  ggtitle("")+
  theme(plot.title = element_text(size=18,vjust=1, hjust = 0, face = "bold"),
        plot.margin = margin(.5, .5, .5, .5, "cm"))

ggsave(file="correlation_level.pdf", width=5, height=5)

### Fig A4

p1= 
  corrdata %>% 
  filter(v_demo == 1)  %>% 
  select("v2x_gender", "v2x_gencl", "v2x_gencs","v2x_genpp", "v2pepwrgen", "v2lgfemleg") %>% 
  rename("empowerment"= v2x_gender,
         "civil liberty"= v2x_gencl, 
         "civil society part"= v2x_gencs, 
         "power dist"= v2pepwrgen, 
         "legislators"= v2lgfemleg, 
         "political part"= v2x_genpp 
  ) %>%
  ggcorr(layout.exp=1, label = TRUE, label_round = 2, hjust=.7)+
  ggtitle("Only democracies")+
  theme(plot.title = element_text(size=18,vjust=1, hjust = 0, face = "bold"),
        plot.margin = margin(.5, .5, .5, .5, "cm"))

p2= 
  corrdata %>% 
  filter(v_demo == 0)  %>% 
  select("v2x_gender", "v2x_gencl", "v2x_gencs","v2x_genpp", "v2pepwrgen", "v2lgfemleg") %>% 
  rename("empowerment"= v2x_gender,
         "civil liberty"= v2x_gencl, 
         "civil society part"= v2x_gencs, 
         "power dist"= v2pepwrgen, 
         "legislators"= v2lgfemleg, 
         "political part"= v2x_genpp 
  ) %>%
  ggcorr(layout.exp=1, label = TRUE, label_round = 2, hjust=.7)+
  ggtitle("Only autocracies")+
  theme(plot.title = element_text(size=18,vjust=1, hjust = 0, face = "bold"),
        plot.margin = margin(.5, .5, .5, .5, "cm"))

p <- grid.arrange(p1, p2, ncol=2)
ggsave(p, file="correlation_level2.pdf", width=10, height=5)


### Fig A5

data <- read.dta13("figA5.dta")
data$dep2 = c(rep(1,8),rep(2,8),rep(3,8),rep(4,8),rep(5,8),rep(6,8))
data$dep2= factor(data$dep2, levels = c(1:6), 
                  labels= c("1. Political empowerment","2. Civil liberty", "3. Civil participation", 
                            "4. Political participation", "5. Power distribution", "6. Legislators (%)"))
data$model = factor(data$model, levels = c(0,1,2,3,4,5,10,15))

ggplot(data) +
  facet_wrap( ~ dep2) + 
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr),
                  size=1.2, fatten = 1.7)+
  # scale_linetype_discrete(labels=c("Intrastate","Interstate"))+
  ylab("")+ 
  xlab("")+
  ggtitle("Effects of Gender Quotas")+
  geom_hline(yintercept=0, lty=2, color="red") + 
  theme_bw()+
  opt 

ggsave(file="figA5.pdf", width=9, height=5.5, units = "in")


### Fig A6

data <- read.dta13("figA6.dta")
data$dep2 = c(rep(1,8),rep(2,8),rep(3,8),rep(4,8),rep(5,8),rep(6,8))
data$dep2= factor(data$dep2, levels = c(1:6), 
                  labels= c("1. Political empowerment","2. Civil liberty", "3. Civil participation", 
                            "4. Political participation", "5. Power distribution", "6. Legislators (%)"))
data$model = factor(data$model, levels = c(0,1,2,3,4,5,10,15))

ggplot(data) +
  facet_wrap( ~ dep2) + 
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr),
                  size=1.2, fatten = 1.7)+
  # scale_linetype_discrete(labels=c("Intrastate","Interstate"))+
  ylab("")+ 
  xlab("")+
  ggtitle("Effects of Gender Quotas in Democracies")+
  geom_hline(yintercept=0, lty=2, color="red") + 
  theme_bw()+
  opt 

ggsave(file="figA6.pdf", width=9, height=5.5, units = "in")


### Figure A7


data <-read.dta13("figA7.dta")

data$dep2 = c(rep(1,8),rep(2,8),rep(3,8),rep(4,8),rep(5,8),rep(6,8))
data$dep2 = factor(data$dep2, levels = c(1:6), 
                   labels= c("1. Political empowerment","2. Civil liberty", "3. Civil participation", 
                             "4. Political participation", "5. Power distribution", "6. Legislators (%)"))
data$model = factor(data$model, levels = c(0,1,2,3,4,5,10,15))

ggplot(data) +
  facet_wrap( ~ dep2) + 
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, group=dep), size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+  
  ylab("")+ 
  xlab("")+
  ggtitle("Effect of War on Women's Political Empowerment and Its Components")+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt

ggsave(file="figA7.pdf", width=10, height=6, units = "in")

### Figure A8

data <- read.dta13("figA8.dta")

data$var <- factor(data$var, levels = c("intra_warDummy", "inter_warDummy"))

data$dep2 = c(rep(1,16),rep(2,16),rep(3,16),rep(4,16),rep(5,16),rep(6,16))
data$dep2= factor(data$dep2, levels = c(1:6), 
                  labels= c("1. Political empowerment","2. Civil liberty", "3. Civil participation", 
                            "4. Political participation", "5. Power distribution", "6. Legislators (%)"))
data$model = factor(data$model, levels = c(0,1,2,3,4,5,10,15))


ggplot(data, aes(group=var, color=var)) +
  facet_wrap( ~ dep2) + 
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Intrastate","Interstate"), values =c("black", "gray60"))+
  # scale_linetype_discrete(labels=c("Intrastate","Interstate"))+
  ylab("")+ 
  xlab("")+
  ggtitle("Distinguishing between Interstate and Intrastate Wars (V-Dem ver.6.2)")+
  geom_hline(yintercept=0, lty=2, color="red") + 
  theme_bw()+
  opt 

ggsave(file="figA8.pdf", width=9, height=5.5, units = "in")


### Figure A9

data <- read.dta13("figA9.dta")

data$var <- factor(data$var, levels = c("intra_warDummy", "inter_warDummy"))

data$dep2 = c(rep(1,16),rep(2,16),rep(3,16),rep(4,16),rep(5,16),rep(6,16))
data$dep2= factor(data$dep2, levels = c(1:6), 
                  labels= c("1. Political empowerment","2. Civil liberty", "3. Civil participation", 
                            "4. Political participation", "5. Power distribution", "6. Legislators (%)"))
data$model = factor(data$model, levels = c(0,1,2,3,4,5,10,15))


ggplot(data, aes(group=var, color=var)) +
  facet_wrap( ~ dep2) + 
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Intrastate","Interstate"), values =c("black", "gray60"))+
  # scale_linetype_discrete(labels=c("Intrastate","Interstate"))+
  ylab("")+ 
  xlab("")+
  ggtitle("Distinguishing between Interstate and Intrastate Wars")+
  geom_hline(yintercept=0, lty=2, color="red") + 
  theme_bw()+
  opt 

ggsave(file="figA9.pdf", width=9, height=5.5, units = "in")


### Fig A10

data <- read.dta13("figA10.dta")
data <- data %>% filter(dep!="drop")
data$dep2 = c(rep(1,8),rep(2,8),rep(3,8),rep(4,8),rep(5,8),rep(6,8))
data$dep2= factor(data$dep2, levels = c(1:6), 
                  labels= c("1. Political empowerment","2. Civil liberty", "3. Civil participation", 
                            "4. Political participation", "5. Power distribution", "6. Legislators (%)"))
data$model = factor(data$model, levels = c(0,1,2,3,4,5,10,15))

ggplot(data) +
  facet_wrap( ~ dep2) + 
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr),
                  size=1.2, fatten = 1.7)+
  ylab("")+ 
  xlab("")+
  ggtitle("Effects of Irregular Leadership Change")+
  geom_hline(yintercept=0, lty=2, color="red") + 
  theme_bw()+
  opt 

ggsave(file="figA10.pdf", width=9, height=5.5, units = "in")

### Figure A11

data <- read.dta13("figA11.dta")
data <- data %>% filter(dep!="drop")

data$dep2 = c(rep(1,8),rep(2,8),rep(3,8),rep(4,8),rep(5,8),rep(6,8))
data$dep2= factor(data$dep2, levels = c(1:6), 
                  labels= c("1. Political empowerment","2. Civil liberty", "3. Civil participation", 
                            "4. Political participation", "5. Power distribution", "6. Legislators (%)"))
data$model = factor(data$model, levels = c(0,1,2,3,4,5,10,15))

ggplot(data) +
  facet_wrap( ~ dep2) + 
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr),
                  size=1.2, fatten = 1.7)+
  ylab("")+ 
  xlab("")+
  ggtitle("Effects of Democratic Regime Change")+
  geom_hline(yintercept=0, lty=2, color="red") + 
  theme_bw()+
  opt 

ggsave(file="figA11.pdf", width=9, height=5.5, units = "in")


## Figure A12

data <- read.dta13("figA12.dta")
data$dep2 = c(rep(1,8),rep(2,8),rep(3,8),rep(4,8),rep(5,8),rep(6,8))
data$dep2= factor(data$dep2, levels = c(1:6), 
                  labels= c("1. Political empowerment","2. Civil liberty", "3. Civil participation", 
                            "4. Political participation", "5. Power distribution", "6. Legislators (%)"))
data$model = factor(data$model, levels = c(0,1,2,3,4,5,10,15))

ggplot(data) +
  facet_wrap( ~ dep2) + 
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr),
                  size=1.2, fatten = 1.7)+
  # scale_linetype_discrete(labels=c("Intrastate","Interstate"))+
  ylab("")+ 
  xlab("")+
  ggtitle("Effects of War in Autocracies")+
  geom_hline(yintercept=0, lty=2, color="red") + 
  theme_bw()+
  opt 

ggsave(file="figA12.pdf", width=9, height=5.5, units = "in")

## Figure A13

data <- read.dta13("figA13.dta")
data$dep2 = c(rep(1,8),rep(2,8),rep(3,8),rep(4,8),rep(5,8),rep(6,8))
data$dep2= factor(data$dep2, levels = c(1:6), 
                  labels= c("1. Political empowerment","2. Civil liberty", "3. Civil participation", 
                            "4. Political participation", "5. Power distribution", "6. Legislators (%)"))
data$model = factor(data$model, levels = c(0,1,2,3,4,5,10,15))

ggplot(data) +
  facet_wrap( ~ dep2) + 
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr),
                  size=1.2, fatten = 1.7)+
  # scale_linetype_discrete(labels=c("Intrastate","Interstate"))+
  ylab("")+ 
  xlab("")+
  ggtitle("Effects of War in Democracies")+
  geom_hline(yintercept=0, lty=2, color="red") + 
  theme_bw()+
  opt 

ggsave(file="figA13.pdf", width=9, height=5.5, units = "in")


## Figure A14

data <- read.dta13("/Users/nk/Dropbox/DATA/Gender/IO-women-empowerment-master/NK replication/Data.dta")

p1 =
  data %>% 
  filter(!is.na(v_demo)) %>% 
  ggplot(aes(x=v2x_gender, linetype=factor(v_demo))) +
  geom_density(size=.7)+
  scale_linetype_manual(labels=c("Autocracy","Democracy"), values =c(2, 1))+
  xlab("Women's political empowerment") + ylab("density") +
  opt 

p2 =
  data %>% 
  filter(!is.na(v_demo)) %>% 
  ggplot(aes(x=v2x_gencl, linetype=factor(v_demo))) +
  geom_density(size=.7)+
  scale_linetype_manual(labels=c("Autocracy","Democracy"), values =c(2, 1))+
  xlab("Women's civil liberty") + ylab("density") +
  opt 

p3 =
  data %>% 
  filter(!is.na(v_demo)) %>% 
  ggplot(aes(x=v2x_gencs, linetype=factor(v_demo))) +
  geom_density(size=.7)+
  scale_linetype_manual(labels=c("Autocracy","Democracy"), values =c(2, 1))+
  xlab("Women's civic participation") + ylab("density") +
  opt 

p4 =
  data %>% 
  filter(!is.na(v_demo)) %>% 
  ggplot(aes(x=v2x_genpp, linetype=factor(v_demo))) +
  geom_density(size=.7)+
  scale_linetype_manual(labels=c("Autocracy","Democracy"), values =c(2, 1))+
  xlab("Women's political participation") + ylab("density") +
  opt 


p5 =
  data %>% 
  filter(!is.na(v_demo)) %>% 
  ggplot(aes(x=v2pepwrgen_re, linetype=factor(v_demo))) +
  geom_density(size=.7)+
  scale_linetype_manual(labels=c("Autocracy","Democracy"), values =c(2, 1))+
  xlab("Power distribution by gender") + ylab("density") +
  opt 

p6 =
  data %>% 
  filter(!is.na(v_demo)) %>% 
  ggplot(aes(x=v2lgfemleg_re, linetype=factor(v_demo))) +
  geom_density(size=.7)+
  scale_linetype_manual(labels=c("Autocracy","Democracy"), values =c(2, 1))+
  xlab("Women's legislative representation") + ylab("density") +
  opt 

p <- grid.arrange(p1, p2, p3, p4,p5, p6, ncol=2)
ggsave(p, file="figA14.pdf", width=10, height=10)


### Fig A15

data <-read.dta13("figA15.dta")

data$coef <- data$coef*100
data$stderr <- data$stderr*100
data$model = factor(data$model, levels = c(0,1,2,3,4,5,10,15))

p1 = 
  data %>% 
  filter(type==1) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr), size=1.2, fatten = 1.7)+  
  ylab("")+ 
  xlab("")+
  ggtitle("1. War and Female Ministers")+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt

p2 = 
  data %>% 
  filter(type==2) %>% 
  ggplot(aes(group=var, color=var)) +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Interstate","Intrastate"), values =c("gray70", "black"))+
  ylab("")+ 
  xlab("")+
  ggtitle("2. Interstate, Intrastate Wars and Female Ministers")+
  geom_hline(yintercept=0, lty=2, color="red") + 
  annotate(geom="text", x=2,2, y=2, label="Interstate", color="gray70", size=3) +
  annotate(geom="text", x=2.4, y=-2, label="Intrastate", color="black", size=3) +
  theme_bw()+
  opt +
  theme(legend.position = "none")

p3 = 
  data %>% 
  filter(type==3 & var =="new_intrawar") %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr),
                  size=1.2, fatten = 1.7)+
  ylab("")+ 
  xlab("")+
  ggtitle("3. New Intrastate War and Female Ministers")+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt

p4 = 
  data %>% 
  filter(type==3 & var =="ongoingintra") %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr),
                  size=1.2, fatten = 1.7)+
  ylab("")+ 
  xlab("")+
  ggtitle("4. Ongoing Intrastate War and Female Ministers")+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt

p5 = 
  data %>% 
  filter(type==3 & var =="recentintra") %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr),
                  size=1.2, fatten = 1.7)+
  ylab("")+ 
  xlab("")+
  ggtitle("5. Recent Intrastate War and Female Ministers")+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt

p6 =
  data %>% 
  filter(type==6) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr), size=1.2, fatten = 1.7)+  
  ylab("")+ 
  xlab("")+
  ggtitle("6. Intrastate War Duration and Female Ministers")+
  geom_hline(yintercept=0, lty=2, color="red") +
  opt

p7 =
  data %>% 
  filter(type==7) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr), size=1.2, fatten = 1.7)+  
  ylab("")+ 
  xlab("")+
  ggtitle("7. Intrastate War Battle Deaths and Female Ministers")+
  geom_hline(yintercept=0, lty=2, color="red") +
  opt


p8 =
  data %>% 
  filter(type==8) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr), size=1.2, fatten = 1.7)+  
  ylab("")+ 
  xlab("")+
  ggtitle("8. Irregular Leadership Changes and Female Ministers")+
  geom_hline(yintercept=0, lty=2, color="red") +
  opt


p <- grid.arrange(p1, p2, p3,  p4, p5, p6, p7, p8, ncol=2)
ggsave(p, file="figA15.pdf", width=10, height=10)


### Fig A16

data <-read.dta13("figA16.dta")
data$var <- factor(data$var, levels = c("recentintra", "intra_warDummy"))
data$model = factor(data$model, levels = c(0,1,2,3,4,5,10,15))

p1 = 
  data %>% 
  filter(type==1) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, group=var, color=var),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Ending","Ongoing"), values =c("black", "gray60"))+
  ylab("")+ 
  xlab("")+
  ggtitle("1. Full sample")+
  geom_hline(yintercept=0, lty=2, color="red")+
  # theme(panel.background = element_rect(fill='transparent'))+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))

p2 = 
  data %>% 
  filter(type==2) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, group=var, color=var),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Ending","Ongoing"), values =c("black", "gray60"))+
  ylab("")+ 
  xlab("")+
  ggtitle("2. Post-1985 period")+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))


p3 = 
  data %>% 
  filter(type==3) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, group=var, color=var),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Ending","Ongoing"), values =c("black", "gray60"))+
  ylab("")+ 
  xlab("")+
  ggtitle("3. East Europe and Central Asia")+
  # scale_y_continuous(breaks = seq(-1.5, .5, by =.5))+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))

p4 = 
  data %>% 
  filter(type==4) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, group=var, color=var),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Ending","Ongoing"), values =c("black", "gray60"))+
  ylab("")+ 
  xlab("")+
  ggtitle("4. Latin America")+
  # scale_y_continuous(breaks = seq(-1.5, .5, by =.5))+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))

p5 = 
  data %>% 
  filter(type==5) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, group=var, color=var),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Ending","Ongoing"), values =c("black", "gray60"))+
  ylab("")+ 
  xlab("")+
  ggtitle("5. Middle East")+
  # scale_y_continuous(breaks = seq(-1.5, .5, by =.5))+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))

p6 = 
  data %>% 
  filter(type==6) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, group=var, color=var),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Ending","Ongoing"), values =c("black", "gray60"))+
  ylab("")+ 
  xlab("")+
  ggtitle("6. South-East Asia")+
  # scale_y_continuous(breaks = seq(-1.5, .5, by =.5))+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))


p7 = 
  data %>% 
  filter(type==7) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, group=var, color=var),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Ending","Ongoing"), values =c("black", "gray60"))+
  ylab("")+ 
  xlab("")+
  ggtitle("7. South Asia")+
  # scale_y_continuous(breaks = seq(-1.5, .5, by =.5))+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))


p8 = 
  data %>% 
  filter(type==8) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, group=var, color=var),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Ending","Ongoing"), values =c("black", "gray60"))+
  ylab("")+ 
  xlab("")+
  ggtitle("8. Sub-Saharan Africa")+
  # scale_y_continuous(breaks = seq(-1.5, .5, by =.5))+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))


p <- grid.arrange(p1, p2, p3, p4,p5, p6, p7, p8, ncol=2)
ggsave(p, file="figA16.pdf", width=10, height=10)


### Fig A17

data <-read.dta13("figA17.dta")
data$model = factor(data$model, levels = c(0,1,2,3,4,5,10,15))


p1 = 
  data %>% 
  filter(type==1) %>% 
  ggplot(aes(group=var, color=var)) +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Ongoing","Ending"), values =c("gray70", "black"))+
  ylab("")+ 
  xlab("")+
  ggtitle("1. Full sample")+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))


p2 = 
  data %>% 
  filter(type==2) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, group=var, color=var),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Ongoing","Ending"), values =c("gray70", "black"))+
  ylab("")+ 
  xlab("")+
  ggtitle("2. Post-1985 period")+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))


p3 = 
  data %>% 
  filter(type==3) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, group=var, color=var),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Ongoing","Ending"), values =c("gray70", "black"))+
  ylab("")+ 
  xlab("")+
  ggtitle("3. East Europe and Central Asia")+
  # scale_y_continuous(breaks = seq(-1.5, .5, by =.5))+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))

p4 = 
  data %>% 
  filter(type==4) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, group=var, color=var),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Ongoing","Ending"), values =c("gray70", "black"))+
  ylab("")+ 
  xlab("")+
  ggtitle("4. Latin America")+
  # scale_y_continuous(breaks = seq(-1.5, .5, by =.5))+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))

p5 = 
  data %>% 
  filter(type==5) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, group=var, color=var),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Ongoing","Ending"), values =c("gray70", "black"))+
  ylab("")+ 
  xlab("")+
  ggtitle("5. Middle East")+
  # scale_y_continuous(breaks = seq(-1.5, .5, by =.5))+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))

p6 = 
  data %>% 
  filter(type==6) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, group=var, color=var),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Ongoing","Ending"), values =c("gray70", "black"))+
  ylab("")+ 
  xlab("")+
  ggtitle("6. South-East Asia")+
  # scale_y_continuous(breaks = seq(-1.5, .5, by =.5))+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))


p7 = 
  data %>% 
  filter(type==7) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, group=var, color=var),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Ongoing","Ending"), values =c("gray70", "black"))+
  ylab("")+ 
  xlab("")+
  ggtitle("7. South Asia")+
  # scale_y_continuous(breaks = seq(-1.5, .5, by =.5))+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))


p8 = 
  data %>% 
  filter(type==8) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, group=var, color=var),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Ongoing","Ending"), values =c("gray70", "black"))+
  ylab("")+ 
  xlab("")+
  ggtitle("8. Sub-Saharan Africa")+
  # scale_y_continuous(breaks = seq(-1.5, .5, by =.5))+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))

p <- grid.arrange(p1, p2, p3, p4,p5, p6, p7, p8, ncol=2)
ggsave(p, file="figA17.pdf", width=10, height=10)

### Fig A18

data <-read.dta13("figA18.dta")
data <- data %>% 
  filter(model!=0) 
data$model = factor(data$model, levels = c(1,2,3,4,5,10,15))

p1 = 
  data %>% 
  filter(type==1) %>% 
  ggplot(aes(group=var, color=var)) +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Ongoing","Ending"), values =c("gray70", "black"))+
  ylab("")+ 
  xlab("")+
  ggtitle("1. Full sample")+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))



p2 = 
  data %>% 
  filter(type==2) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, group=var, color=var),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Ongoing","Ending"), values =c("gray70", "black"))+
  ylab("")+ 
  xlab("")+
  ggtitle("2. Post-1985 period")+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))


p3 = 
  data %>% 
  filter(type==3) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, group=var, color=var),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Ongoing","Ending"), values =c("gray70", "black"))+
  ylab("")+ 
  xlab("")+
  ggtitle("3. East Europe and Central Asia")+
  # scale_y_continuous(breaks = seq(-1.5, .5, by =.5))+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))

p4 = 
  data %>% 
  filter(type==4) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, group=var, color=var),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Ongoing","Ending"), values =c("gray70", "black"))+
  ylab("")+ 
  xlab("")+
  ggtitle("4. Latin America")+
  # scale_y_continuous(breaks = seq(-1.5, .5, by =.5))+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))

p5 = 
  data %>% 
  filter(type==5) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, group=var, color=var),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Ongoing","Ending"), values =c("gray70", "black"))+
  ylab("")+ 
  xlab("")+
  ggtitle("5. Middle East")+
  # scale_y_continuous(breaks = seq(-1.5, .5, by =.5))+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))

p6 = 
  data %>% 
  filter(type==6) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, group=var, color=var),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Ongoing","Ending"), values =c("gray70", "black"))+
  ylab("")+ 
  xlab("")+
  ggtitle("6. South-East Asia")+
  # scale_y_continuous(breaks = seq(-1.5, .5, by =.5))+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))


p7 = 
  data %>% 
  filter(type==7) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, group=var, color=var),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Ongoing","Ending"), values =c("gray70", "black"))+
  ylab("")+ 
  xlab("")+
  ggtitle("7. South Asia")+
  # scale_y_continuous(breaks = seq(-1.5, .5, by =.5))+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))


p8 = 
  data %>% 
  filter(type==8) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, group=var, color=var),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  scale_color_manual(labels=c("Ongoing","Ending"), values =c("gray70", "black"))+
  ylab("")+ 
  xlab("")+
  ggtitle("8. Sub-Saharan Africa")+
  # scale_y_continuous(breaks = seq(-1.5, .5, by =.5))+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))


p <- grid.arrange(p1, p2, p3, p4,p5, p6, p7, p8, ncol=2)

ggsave(p, file="figA18.pdf", width=10, height=10)


### Fig A19

data <-read.dta13("figA19a.dta")
data$model = factor(data$model, levels = c(0,1,2,3,4,5,10,15))

p1 = 
  data %>% 
  filter(data$var=="trans_intra_warDummy_post3") %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr), size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  ylab("")+ 
  xlab("")+
  ggtitle("Accompanying democratization (Polity IV based)")+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt

p2 = 
  data %>% 
  filter(data$var=="notrans_intra_warDummy_post3") %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr), size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  ylab("")+ 
  xlab("")+
  ggtitle("Accompanying no democratization (Polity IV based)")+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt

data <-read.dta13("figA19b.dta")
data$model = factor(data$model, levels = c(0,1,2,3,4,5,10,15))

p3 = 
  data %>% 
  filter(data$var=="trans2_intra_warDummy_post3") %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr), size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  ylab("")+ 
  xlab("")+
  ggtitle("Accompanying democratization (V-Dem Poliarchy based)")+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt

p4 = 
  data %>% 
  filter(data$var=="notrans2_intra_warDummy_post3") %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr), size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  ylab("")+ 
  xlab("")+
  ggtitle("Accompanying no democratization (V-Dem Poliarchy based)")+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt


data <-read.dta13("figA19c.dta")
data$model = factor(data$model, levels = c(0,1,2,3,4,5,10,15))

p5 = 
  data %>% 
  filter(data$var=="irregular_intra_warDummy_post3") %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr), size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  ylab("")+ 
  xlab("")+
  ggtitle("Accompanying irregular leader change")+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt

p6 = 
  data %>% 
  filter(data$var=="noirregular_intra_warDummy_post3") %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr), size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  ylab("")+ 
  xlab("")+
  ggtitle("Accompanying no irregular leader change")+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt


p <- grid.arrange(p1, p2, p3,p4, p5, p6, ncol=2)
ggsave(p, file="figA19.pdf", width=10, height=10)

### Fig A20

data <-read.dta13("BB5.dta")
data$model = factor(data$model, levels = c(1,2,3,4,5,10,15))
p1<-
  data %>% 
  filter(type==1) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  ylab("")+ 
  xlab("")+
  ggtitle("Effects of peace agreements")+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))

data <-read.dta13("BB6.dta")
data$model = factor(data$model, levels = c(1,2,3,4,5,10,15))
p2<-
  data %>% 
  filter(type==1) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  ylab("")+ 
  xlab("")+
  ggtitle("Effects of peace agreements in SSF")+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))


data <-read.dta13("BB7.dta")
data$model = factor(data$model, levels = c(1,2,3,4,5,10,15))
p3<-
  data %>% 
  filter(type==1) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  ylab("")+ 
  xlab("")+
  ggtitle("Effects of peace agreements including gender provision")+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))

data <-read.dta13("BB8.dta")
data$model = factor(data$model, levels = c(1,2,3,4,5,10,15))
p4<-
  data %>% 
  filter(type==1) %>% 
  ggplot() +
  geom_pointrange(aes(x= factor(model), y=coef, ymin=coef-1.96*stderr, ymax=coef+1.96*stderr),
                  size=1.2, fatten = 1.7, position=position_dodge(width = 0.7))+
  ylab("")+ 
  xlab("")+
  ggtitle("Effects of peace agreements including gender provision in SSF")+
  geom_hline(yintercept=0, lty=2, color="red")+
  opt+
  guides(color = guide_legend(override.aes = list(size = 0.5))) +
  theme(legend.box.margin = margin(0, 0, 0, 0))

p <- grid.arrange(p1, p2, p3, p4, ncol=2)
ggsave(p, file="figA20.pdf", width=12, height=8)


### Figure A21

p1=
wb_dat %>% 
  filter(COWcode == 2 & year >= 1970) %>% 
  ggplot() + 
  theme_bw() +   
  geom_line(aes(x=year, y= v2pepwrgen), size=1)+
  ggtitle("United States")+
  ylab("")+ 
  ylim(0,3.5)+
  
  xlab("")+
  opt

p2=
wb_dat %>% 
  filter(COWcode == 140 & year >= 1970) %>% 
  ggplot() + 
  theme_bw() +   
  geom_line(aes(x=year, y= v2pepwrgen), size=1)+
  ggtitle("Brazil")+
  ylab("")+ 
  ylim(0,3.5)+
  
  xlab("")+
  opt

p3=
wb_dat %>% 
  filter(COWcode == 200 & year >= 1970) %>% 
  ggplot() + 
  theme_bw() +   
  geom_line(aes(x=year, y= v2pepwrgen), size=1)+
  ggtitle("United Kingdom")+
  ylab("")+ 
  ylim(0,3.5)+
  
  xlab("")+
  opt

p4=
wb_dat %>% 
  filter(COWcode == 220 & year >= 1970) %>% 
  ggplot() + 
  theme_bw() +   
  geom_line(aes(x=year, y= v2pepwrgen), size=1)+
  ggtitle("France")+
  ylab("")+ 
  ylim(0,3.5)+
  
  xlab("")+
  opt

p6=
  wb_dat %>% 
  filter(COWcode == 369 & year >= 1970) %>% 
  ggplot() + 
  theme_bw() +   
  geom_line(aes(x=year, y= v2pepwrgen), size=1)+
  ggtitle("Ukraine")+
  ylab("")+ 
  ylim(0,3.5)+
  
  xlab("")+
  opt

p5=
wb_dat %>% 
  filter(COWcode == 517 & year >= 1970) %>% 
  ggplot() + 
  theme_bw() +   
  geom_line(aes(x=year, y= v2pepwrgen), size=1)+
  ggtitle("Rwanda")+
  ylab("")+ 
  ylim(0,3.5)+
  
  xlab("")+
  opt



p7=
wb_dat %>% 
  filter(COWcode == 450 & year >= 1970) %>% 
  ggplot() + 
  theme_bw() +   
  geom_line(aes(x=year, y= v2pepwrgen), size=1)+
  ggtitle("Liberia")+
  ylab("")+ 
  ylim(0,3.5)+
  
  xlab("")+
  opt

p8=
wb_dat %>% 
  filter(COWcode == 713 & year >= 1970) %>% 
  ggplot() + 
  theme_bw() +   
  geom_line(aes(x=year, y= v2pepwrgen), size=1)+
  ggtitle("Taiwan")+
  ylab("")+ 
  ylim(0,3.5)+
  
  xlab("")+
  opt

p9=
wb_dat %>% 
  filter(COWcode == 732 & year >= 1970) %>% 
  ggplot() + 
  theme_bw() +   
  geom_line(aes(x=year, y= v2pepwrgen), size=1)+
  ggtitle("South Korea")+
  ylab("")+ 
  ylim(0,3.5)+
  
  xlab("")+
  opt

p10= 
wb_dat %>% 
  filter(COWcode == 800 & year >= 1970) %>% 
  ggplot() + 
  theme_bw() +   
  geom_line(aes(x=year, y= v2pepwrgen), size=1)+
  ggtitle("Thailand")+
  ylab("")+ 
  ylim(0,3.5)+
  xlab("")+
  opt

p11= 
  wb_dat %>% 
  filter(COWcode == 750 & year >= 1970) %>% 
  ggplot() + 
  theme_bw() +   
  geom_line(aes(x=year, y= v2pepwrgen), size=1)+
  ggtitle("India")+
  ylab("")+ 
  ylim(0,3.5)+
  xlab("")+
  opt

p12= 
  wb_dat %>% 
  filter(COWcode == 310 & year >= 1970) %>% 
  ggplot() + 
  theme_bw() +   
  geom_line(aes(x=year, y= v2pepwrgen), size=1)+
  ggtitle("Hungary")+
  ylab("")+ 
  ylim(0,3.5)+
  xlab("")+
  opt

p <- grid.arrange(p1, p2, p3, p4, p12, p6,  p5, p7, p8, p9, p10,p11, ncol=4)
ggsave(p, file="figA21.pdf", width=12, height=12)


## Figure A22-A23

wb_dat <-read.dta13("figA22.dta")

ggplot(wb_dat[wb_dat$year == 2021 & wb_dat$v2pepwrgen >1.04 ,], aes(x = reorder(country_name, v2pepwrgen), y = v2pepwrgen)) +
  theme_bw() + 
  coord_flip()+
  geom_bar(stat = "identity", alpha=.8, width = .5)+
  ylab("Power distribution by gender") + 
  xlab("") + 
  opt

ggsave(file="FigA23a.pdf", width=12, height=15)

ggplot(wb_dat[wb_dat$year == 2021 & wb_dat$v2pepwrgen <1.04 ,], aes(x = reorder(country_name, v2pepwrgen), y = v2pepwrgen)) +
  theme_bw() + 
  coord_flip()+
  geom_bar(stat = "identity", alpha=.8, width = .5)+
  ylab("Power distribution by gender") + 
  xlab("") + 
  opt

ggsave(file="FigA23b.pdf", width=12, height=15)
